//
//  ChannelShowController.swift
//  DoctorVisits
//
//  Created by lanou3g on 16/2/29.
//  Copyright © 2016年 SHH. All rights reserved.
//

import UIKit

class ChannelShowController: UIViewController {
    
    var infoImageV:UIImageView? //影视图片
    var star:UILabel?  // 星星
    var numberL:UILabel? //剧集数
    var grade:UILabel?//评分
    var actors:UILabel?//主演
    var actorsS:UILabel?//主演人员
    var yearL:UILabel?//年份
    var time:UILabel? //时间
    var sourceL:UILabel?//播放来源
    var sourceBtn:UIButton?//播放来源选项
    var showImageV:UIImageView?//小图标
    var playBtn:UIButton?//播放
    var menuV:UIView?//菜单
    var pageV:UILabel? // 跟随标志
    
    var intro:UIButton?//简介
    var episode:UIButton?//剧集
    var correlation:UIButton?//相关
    
    //    let introLV = ChannelIntorView()
    var introLV:UIView?
    var intorLabel:UILabel?//简介内容
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "寂寞空庭春欲晚"
        self.view.backgroundColor = UIColor.whiteColor()
        
        addViews()
        
    }
    
    func addViews() -> Void{
        infoImageV = UIImageView(frame: CGRectMake(self.view.frame.size.width*0.03, self.view.frame.size.height*0.12, self.view.frame.size.width*0.3, self.view.frame.size.height*0.23))
        infoImageV?.backgroundColor = UIColor.redColor()
        self.view.addSubview(infoImageV!)
        
        numberL = UILabel(frame: CGRectMake(0,(self.infoImageV?.frame.size.height)!*0.83,(self.infoImageV?.frame.size.width)!,(self.infoImageV?.frame.size.height)!*0.17))
        numberL?.text = "37集全"
        numberL?.backgroundColor = UIColor.whiteColor()
        numberL?.alpha = 0.7
        numberL?.textAlignment = .Right
        numberL?.font = UIFont.systemFontOfSize(13)
        infoImageV?.addSubview(numberL!)
        
        star = UILabel(frame: CGRectMake(self.view.frame.size.width*0.38,self.view.frame.size.height*0.12, self.view.frame.size.width*0.32, self.view.frame.size.height*0.03))
        star?.text = "❤️❤️❤️❤️❤️"
        //        star?.textAlignment = .Center
        star?.font = UIFont.systemFontOfSize(13)
        //        star?.backgroundColor = UIColor.purpleColor()
        self.view.addSubview(star!)
        
        grade = UILabel(frame: CGRectMake(self.view.frame.size.width*0.65,self.view.frame.size.height*0.1205,self.view.frame.size.width*0.25,self.view.frame.size.height*0.03))
        grade?.text = "9.8"
        grade?.textAlignment = .Left
        grade?.transform = CGAffineTransformMakeRotation(0.1)
        grade?.font = UIFont.systemFontOfSize(23, weight: 0)
        //        grade?.backgroundColor = UIColor.greenColor()
        self.view.addSubview(grade!)
        
        actors = UILabel(frame: CGRectMake(self.view.frame.size.width*0.38,self.view.frame.size.height*0.16,self.view.frame.size.width*0.11,self.view.frame.size.height*0.03))
        actors?.text = "主演:"
        actors?.font = UIFont.systemFontOfSize(13)
        //        actors?.backgroundColor = UIColor.blueColor()
        self.view.addSubview(actors!)
        
        actorsS = UILabel(frame: CGRectMake(self.view.frame.size.width*0.46,self.view.frame.size.height*0.16,self.view.frame.size.width*0.42,self.view.frame.size.height*0.03))
        actorsS?.text = "刘恺威,郑爽,米雪,张彬彬,涨涨涨"
        actorsS?.font = UIFont.systemFontOfSize(13)
        self.view.addSubview(actorsS!)
        
        yearL = UILabel(frame: CGRectMake(self.view.frame.size.width*0.38,self.view.frame.size.height*0.2,self.view.frame.size.width*0.1,self.view.frame.size.height*0.03))
        yearL?.text = "年份:"
        yearL?.font = UIFont.systemFontOfSize(13)
        self.view.addSubview(yearL!)
        
        time = UILabel(frame: CGRectMake(self.view.frame.size.width*0.48,self.view.frame.size.height*0.2,self.view.frame.size.width*0.42,self.view.frame.size.height*0.03))
        time?.text = "2016-02-01"
        time?.font = UIFont.systemFontOfSize(13)
        self.view.addSubview(time!)
        
        
        sourceL = UILabel(frame: CGRectMake(self.view.frame.size.width*0.38,self.view.frame.size.height*0.24,self.view.frame.size.width*0.17,self.view.frame.size.height*0.03))
        sourceL?.text = "播放来源"
        sourceL?.font = UIFont.systemFontOfSize(13)
        //        sourceL?.backgroundColor = UIColor.redColor()
        self.view.addSubview(sourceL!)
        
        
        sourceBtn = UIButton(frame: CGRectMake(self.view.frame.size.width*0.55,self.view.frame.size.height*0.24,self.view.frame.size.width*0.35,self.view.frame.size.height*0.03))
        sourceBtn?.setTitle("   乐视网  ⊿", forState: UIControlState.Normal)
        sourceBtn?.addTarget(self, action: Selector("pullAction"), forControlEvents: UIControlEvents.TouchUpInside)
        sourceBtn?.titleLabel!.font = UIFont.systemFontOfSize(13)
        //        sourceBtn?.backgroundColor = UIColor.yellowColor()
        sourceBtn?.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.view.addSubview(sourceBtn!)
        
        
        showImageV = UIImageView(frame: CGRectMake((self.sourceBtn?.frame.size.width)!*0.12, 0, (self.sourceBtn?.frame.size.width)!*0.15, (self.sourceBtn?.frame.size.height)!))
        showImageV?.image = UIImage(named: "play_logo_letv")
        sourceBtn?.addSubview(showImageV!)
        
        playBtn = UIButton(frame: CGRectMake(self.view.frame.size.width*0.38,self.view.frame.size.height*0.288,self.view.frame.size.width*0.2,self.view.frame.size.height*0.06))
        playBtn?.backgroundColor = UIColor.blueColor()
        playBtn?.setTitle("播放", forState: UIControlState.Normal)
        playBtn?.titleLabel?.font = UIFont.systemFontOfSize(20)
        self.view.addSubview(playBtn!)
        playBtn?.addTarget(self, action: Selector("playMoveieAction"), forControlEvents: UIControlEvents.TouchUpInside)
        
        intro = UIButton(frame: CGRectMake(0,self.view.frame.size.height*0.37,self.view.frame.size.width*0.33,self.view.frame.size.height*0.06))
        intro?.setTitle("简介", forState: UIControlState.Normal)
        //        intro?.backgroundColor = UIColor.grayColor()
        intro?.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        intro?.titleLabel?.font = UIFont.systemFontOfSize(20)
        self.view.addSubview(intro!)
        intro?.addTarget(self, action: Selector("introAction"), forControlEvents: UIControlEvents.TouchUpInside)
        
        episode = UIButton(frame: CGRectMake(self.view.frame.size.width*0.33,self.view.frame.size.height*0.37,self.view.frame.size.width*0.33,self.view.frame.size.height*0.06))
        episode?.setTitle("剧集", forState: UIControlState.Normal)
        episode?.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        episode?.titleLabel?.font = UIFont.systemFontOfSize(20)
        self.view.addSubview(episode!)
        episode?.addTarget(self, action: Selector("episodeAction"), forControlEvents: UIControlEvents.TouchUpInside)
        
        correlation = UIButton(frame: CGRectMake(self.view.frame.size.width*0.66,self.view.frame.size.height*0.37,self.view.frame.size.width*0.33,self.view.frame.size.height*0.06))
        correlation?.setTitle("相关", forState: UIControlState.Normal)
        correlation?.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        correlation?.titleLabel?.font = UIFont.systemFontOfSize(20)
        self.view.addSubview(correlation!)
        correlation?.addTarget(self, action: Selector("correlationAction"), forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
        introLV = UIView()
        introLV!.frame = CGRectMake(0,self.view.frame.size.height*0.44,self.view.frame.size.width,self.view.frame.size.height*0.44)
        introLV!.backgroundColor = UIColor.groupTableViewBackgroundColor()
        self.view.addSubview(introLV!)
        
        
        intorLabel = UILabel()
        intorLabel?.text = "康熙八年，鳌拜被擒，声势浩大的余党清剿随之开始。忠臣阿布鼐受冤遭受灭门之灾，年仅十岁的幼女良儿目睹全家被屠，侥幸逃脱。逃亡路上偶遇少年康熙，两人在不知对方身份的情况下经历生死之劫，彼此留下深刻印象，更许下再次见面的约定。而后良儿投奔表哥纳兰容若（张彬彬饰），却意外失忆。容若为保护良儿为其改名卫琳琅（郑爽饰），留在府中照顾。时光荏苒，容若与琳琅一起长大，青梅竹马，感情笃深，但纳兰明珠忌惮琳琅身份引来祸患，偷偷把她送入宫中为婢。"
        intorLabel?.numberOfLines = 0
        let maxHeight:CGSize = (intorLabel?.sizeThatFits(CGSizeMake(((introLV?.frame.size.width)!*0.84),CGFloat(MAXFLOAT))))!
        intorLabel?.frame = CGRectMake(introLV!.frame.size.width*0.08,introLV!.frame.size.height*0.1,introLV!.frame.size.width*0.84,maxHeight.height)
        
        introLV!.addSubview(intorLabel!)
        
        pageV = UILabel()
        pageV?.frame = CGRectMake(self.view.frame.size.width*0.1,self.view.frame.size.height*0.435,self.view.frame.size.width*0.13,self.view.frame.size.height*0.002)
        pageV?.backgroundColor = UIColor.redColor()
        self.view.addSubview(pageV!)
        
        
    }
    
    func playMoveieAction() -> Void{
        
        let playV = ViewController()
        self.navigationController?.pushViewController(playV, animated: true)
        
    }
    
    //  点击相关按钮事件
    func introAction() -> Void{
        
        introLV!.removeFromSuperview()
        intorLabel?.removeFromSuperview()
        
        //        let introLV = ChannelIntorView()
        introLV!.frame = CGRectMake(0,self.view.frame.size.height*0.44,self.view.frame.size.width,self.view.frame.size.height*0.44)
        introLV!.backgroundColor = UIColor.groupTableViewBackgroundColor()
        
        self.view.addSubview(introLV!)
        
        
        let maxHeight:CGSize = (intorLabel?.sizeThatFits(CGSizeMake(((introLV?.frame.size.width)!*0.84),CGFloat(MAXFLOAT))))!
        
        intorLabel?.text = "康熙八年，鳌拜被擒，声势浩大的余党清剿随之开始。忠臣阿布鼐受冤遭受灭门之灾，年仅十岁的幼女良儿目睹全家被屠，侥幸逃脱。逃亡路上偶遇少年康熙，两人在不知对方身份的情况下经历生死之劫，彼此留下深刻印象，更许下再次见面的约定。而后良儿投奔表哥纳兰容若（张彬彬饰），却意外失忆。容若为保护良儿为其改名卫琳琅（郑爽饰），留在府中照顾。时光荏苒，容若与琳琅一起长大，青梅竹马，感情笃深，但纳兰明珠忌惮琳琅身份引来祸患，偷偷把她送入宫中为婢。"
        intorLabel?.numberOfLines = 0
        intorLabel?.frame = CGRectMake(introLV!.frame.size.width*0.08,introLV!.frame.size.height*0.1,introLV!.frame.size.width*0.84,maxHeight.height)
        //        intorLabel?.backgroundColor = UIColor.redColor()
        
        introLV!.addSubview(intorLabel!)
        
        pageV?.frame = CGRectMake(self.view.frame.size.width*0.1,self.view.frame.size.height*0.435,self.view.frame.size.width*0.13,self.view.frame.size.height*0.002)
        
    }
    
    
    //    点击剧集事件
    func episodeAction() -> Void{
        
        
        
        introLV!.removeFromSuperview()
        intorLabel?.removeFromSuperview()
        
        
        pageV?.frame = CGRectMake(self.view.frame.size.width*0.43,self.view.frame.size.height*0.435,self.view.frame.size.width*0.13,self.view.frame.size.height*0.002)
        
        let a = ChannelEpisodeController()
        self.addChildViewController(a)
        self.view.addSubview(a.view)
        
        a.view.frame = CGRectMake(0,self.view.frame.size.height*0.44,self.view.frame.size.width,self.view.frame.size.height*0.44)
        
        
        
        
    }
    
    
    //    点击相关事件
    func correlationAction() -> Void{
        
    }
    
    //    点击播放来源 弹出菜单与动画效果
    func pullAction() -> Void{
        
        menuV = UIView(frame: CGRectMake(self.view.frame.size.width*0.7,self.view.frame.size.height*0.28,0,0))
        //        menuV = UIView(frame: CGRectMake(0,0,0,0))
        menuV?.backgroundColor = UIColor.grayColor()
        self.view.addSubview(menuV!)
        
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(0.25)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseOut)
        UIView.setAnimationRepeatAutoreverses(false)
        UIView.setAnimationDelegate(self)
        //        menuV?.alpha = 0.5
        menuV?.frame = (frame: CGRectMake(self.view.frame.size.width*0.7,self.view.frame.size.height*0.28,self.view.frame.size.width*0.28,self.view.frame.size.height*0.15))
        UIView.commitAnimations()
        //        menuV?.performSelector(Selector("keepPosition"), withObject: nil, afterDelay: 4)
        
        
        sourceBtn?.removeFromSuperview()
        showImageV?.removeFromSuperview()
        
        sourceBtn = UIButton(frame: CGRectMake(self.view.frame.size.width*0.55,self.view.frame.size.height*0.24,self.view.frame.size.width*0.35,self.view.frame.size.height*0.03))
        sourceBtn?.setTitle("   乐视网  ⊿", forState: UIControlState.Normal)
        sourceBtn?.addTarget(self, action: Selector("backAction"), forControlEvents: UIControlEvents.TouchUpInside)
        sourceBtn?.titleLabel!.font = UIFont.systemFontOfSize(13)
        //        sourceBtn?.backgroundColor = UIColor.yellowColor()
        sourceBtn?.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.view.addSubview(sourceBtn!)
        
        
        showImageV = UIImageView(frame: CGRectMake((self.sourceBtn?.frame.size.width)!*0.12, 0, (self.sourceBtn?.frame.size.width)!*0.15, (self.sourceBtn?.frame.size.height)!))
        showImageV?.image = UIImage(named: "play_logo_letv")
        sourceBtn?.addSubview(showImageV!)
        
        
        
        
    }
    
    func backAction() ->Void{
        menuV?.removeFromSuperview()
        sourceBtn?.addTarget(self, action: Selector("pullAction"), forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
